package com.iotechn.unimall.biz.service.service;

import com.iotechn.unimall.data.domain.ServerDO;
import com.iotechn.unimall.data.vo.TreeVO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ServiceBizService {

    /**
     * 递归树
     * @param serverDOS
     * @param pid
     * @return
     */
    public List<TreeVO> selectRegion(List<ServerDO> serverDOS, Long pid){
        List<TreeVO> result = new ArrayList<>();
        serverDOS.forEach(e ->{
            if(e.getPid().equals(pid)){
                TreeVO treeVO = new TreeVO();
                treeVO.setLabel(e.getName());
                treeVO.setUrl(e.getImgUrl());
                treeVO.setValue(e.getId());
                // 查询下级元素
                treeVO.setChildren(selectRegion(serverDOS,e.getId()));
                result.add(treeVO);
            }
        });
        return result;
    }
}
